from django.db import models


# Create your models here.

class Permission(models.Model):
    """
    权限
    """
    title = models.CharField(max_length=32,default="")  # 权限名
    url = models.CharField(max_length=128, null=True, blank=True)  #
    topid = models.IntegerField(default=0)
    icon = models.CharField(max_length=52, null=True, default='ic ic-homepage-fill')
    target = models.CharField(max_length=32, null=True, default='_self')
    status = models.IntegerField(default="1")
    type = models.IntegerField(default="1")  # 权限的类型，1为显示菜单，2为非显示请求接口
    parent = models.ForeignKey("Permission", null=True, blank=True, on_delete=models.CASCADE)

    def __str__(self):
        # 显示带菜单前缀的权限
        return self.title

    class Meta:
        verbose_name = '权限菜单'
        verbose_name_plural = '权限菜单'
        db_table = "Permission"


class Role(models.Model):
    """
    角色：绑定权限
    """
    title = models.CharField(max_length=32, unique=True)
    status=models.BooleanField(default=1,null=True,blank=True)
    remark=models.CharField(max_length=64)
    permissions = models.ManyToManyField("Permission")
    # 定义角色和权限的多对多关系

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '角色'
        verbose_name_plural = '角色'
        db_table = "Role"




class UserInfo(models.Model):
    """
    用户：划分角色
    """
    username = models.CharField(max_length=32,null=True,blank=True)  # 用户名
    password = models.CharField(max_length=64)  # 密码
    nickname = models.CharField(max_length=32,default='用户')  # 昵称
    status = models.BooleanField(default=True)  # 状态
    email = models.EmailField(null=True)  # 邮箱
    signature = models.CharField(max_length=32, default="我不知道我是瓶子，还是瓶子里的一滴水", null=True)  # 签名
    roles = models.ManyToManyField("Role")  # 角色
    re_time = models.DateTimeField(auto_now_add=True,null=True,blank=True)  # 注册时间
    last_login = models.DateTimeField(auto_now=True,null=True,blank=True)  # 最后登录
    tokens = models.CharField("token", max_length=500, null=True, blank=True)  # token
    create_token = models.CharField("token创建时间", max_length=30, null=True, blank=True)  # token创建时间
    end_token = models.CharField("token过期时间", max_length=30, null=True, blank=True)     # 过期时间

    # 定义用户和角色的多对多关系
    def __str__(self):
        return self.nickname

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = '用户   '
        db_table = "UserInfo"

class Questiontype(models.Model):
    typename=models.CharField("类型",max_length=33)
    checked=models.BooleanField('修改状态',default=False)
    class Meta:
        verbose_name = '题类型'
        verbose_name_plural = '题类型'
        db_table = "Questiontype"
    pass
class Questions(models.Model):
    title=models.CharField("题目",max_length=88)
    content=models.CharField("内容",max_length=200)
    answer=models.CharField("答案",max_length=200)
    types=models.ForeignKey(to='Questiontype',null=True,on_delete=models.CASCADE)
    checked=models.BooleanField("选中",default=False)
    class Meta:
        verbose_name = '题目'
        verbose_name_plural = '题目'
        db_table = "Questions"

class Users(models.Model):
    name=models.CharField('姓名',max_length=33)
    time=models.DateTimeField('时间',auto_now=True,auto_created=True)
    address=models.CharField("地址",max_length=33,null=True,blank=True)
    class Meta:
        db_table='users'

class tabs(models.Model):
    description=models.CharField('描述',max_length= 50)
    status=models.CharField('状态',default=1,max_length=3)
    class Meta:
        db_table='tabs'